package ps3838

import (
	"net/http"
	"net/http/cookiejar"
	"sync"
	"time"

	"lottery/constant"
	"lottery/models"
	"lottery/services/lottery"
)

type PS3838Factory struct {
	once *sync.Once
}

func NewPS3838Factory() *PS3838Factory {
	return &PS3838Factory{
		once: new(sync.Once),
	}
}

func (p *PS3838Factory) New(agentInfo *models.Agent) lottery.ILottery {
	// 环境初始化
	p.once.Do(initPS3838Env)
	client := new(http.Client)
	client.Timeout = 10 * time.Second
	jar, _ := cookiejar.New(nil)
	client.Jar = jar
	return &Ps3838{
		userAgent:    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36",
		agentInfo:    agentInfo,
		jar:          jar,
		client:       client,
		wg:           new(sync.WaitGroup),
		stoped:       make(chan struct{}),
		gameChan:     make(chan []*models.Game, 100),
		gameDataChan: make(chan []*models.GameData, 100),
	}
}

func (p *PS3838Factory) Platform() int {
	return constant.PS3838
}
